package engine.logic
{
	import engine.display.newAttack.AttackLogic;
	import engine.logic.loading.LoadingLogic;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.loader.SwfLoader;

	public class EffectLoadManager
	{
		
		//是否加载特效资源
		public static var isLoadEffectSwf		:Boolean	=	false;
		
		public static var effectLoadIsShow	:Boolean	=	false;
		
		private static var _isNxLoaderProxyShowing	:Boolean	=	false;
		
		public static function loadEffectSwf():void
		{
			if(!isLoadEffectSwf)
			{
				isLoadEffectSwf	=	true;
//				SwfLoader.StartLoad(
//					StageInfo.swfResPath + "effect.swf",
//					null,
//					onLoadEffectSuccess,
//					[onLoadingEffectHandle]);
				
//				loadKungfuEffect();
			}
		}
		public static function loadKungfuEffect():void
		{
//			if(!isLoadEffectSwf)
			{
				SwfLoader.StartLoad(
					StageInfo.swfResPath + "kungfu.swf",
					null,
					onLoadKungfuSuccess);
			}
		}
		private static function onLoadKungfuSuccess(val:DisplayObject,plist:Array=null):void
		{
			if (val != null )
			{
				ResManager.SaveRes("kungfu.swf", val);
			}
			else
			{
//				isLoadEffectSwf	=	false;
			}
		}
		private static function onLoadEffectSuccess(val:DisplayObject, pList:Array = null):void
		{
			if (val != null )
			{
				ResManager.SaveRes("effect.swf", val);
				loadKungfuEffect();
			}
			else
			{
				isLoadEffectSwf	=	false;
			}
		}
		
		private static function onLoadingEffectHandle(event:Event):void
		{
			if(event.type == ProgressEvent.PROGRESS && effectLoadIsShow)
			{
				var e:ProgressEvent	=	event as ProgressEvent;
				if(AttackLogic.getInstance().fighting)
				{
					if(!_isNxLoaderProxyShowing)
					{
						NxLoaderProxy.show();
						_isNxLoaderProxyShowing	=	true;
					}
					
					NxLoaderProxy.setProgress(e.bytesLoaded*100/e.bytesTotal,StaticIni.getSwfLangStr("UIStr_Load_Effect"),true);
				}
				else
				{
					LoadingLogic.getInstance().setProcess(e.bytesLoaded*100/e.bytesTotal,StaticIni.getSwfLangStr("UIStr_Load_Effect"));
				}
				
			}
		}
	}
}